package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Reference
    private PermissionService permissionService;

    @RequestMapping("/findAll")
    public Result findAll(){
        try {
            List<Permission> permissionList = permissionService.findAll();
            return new Result(true,MessageConstant.QUERY_Permission_SUCCESS,permissionList);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_Permission_FAIL);
        }
    }

    /**
     * 根据角色信息查询权限的id
     */
    @RequestMapping("/findPermissionIdsByRole")
    public Result findPermissionIdsByRole(Integer id){
        System.out.println("id ==11111111111111111111111111111111111 " + id);

        try {
            List<Integer> list = permissionService.findPermissionIdsByRole(id);
            System.out.println("list ====================================== " + list);
            return new Result(true,MessageConstant.QUERY_Permission_SUCCESS,list);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_Permission_FAIL);
        }

    }
}
